<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2>今天天气很{{info}},{{x}}</h2>
        <!--    绑定事件的时候@xxx=yyy可以写简单的语句  但是逻辑过于复杂就不推荐了    -->
        <!--    -->
        <button @click="changeWeather">给爷变</button>
    </div>
    <script>
        Vue.config.productionTip = false
        const vm = new Vue({
            el:'#root',
            data:{
                isHot:true,
                x:1
            },
            methods: {
                changeWeather(){
                    this.isHot=!this.isHot
                    this.x++;
                }
            },
            computed:{
                info(){
                    return this.isHot?'炎热':'凉爽'
                }
            },
            watch:{
                isHot:{
                    //初始化时直接让handler被调用
                    immediate:true,
                    //isHot发生改变时 handler被调用
                    handler(newValue,oldValue){
                        console.log('isHot被修改了',newValue,oldValue)
                    }
                }
            }
        })
        // vm.$watch('isHot',{
        //     //初始化时直接让handler被调用
        //     immediate:true,
        //     //isHot发生改变时 handler被调用
        //     handler(newValue,oldValue){
        //         console.log('isHot被修改了',newValue,oldValue)
        //     }
        // })
        
    </script>
</body>
</html>